#!/usr/local/bin/perl
#
# HTMLBBS v0.94 Eric Murray 4/14/95
#
# posts a message to a topic file in an HTMLBBS.
#
# eric murray, ericm@lne.com
#
# This program is copyright 1995 by Eric Murray.
#
# It may be used for commercial use only by prior arrangement
# with the author. It may not in any circumstances be resold to
# another party. You are free to make non-commercial use of
# the ideas and algorithms that this code represents as long
# as you do not merely re-phrase it or port it to another
# language. If you use any of the code from this program in
# another program, that resulting program must be placed
# under the GNU Copyleft or similar agreement and source code
# from that program must be made available to all who want it.
#
#
# this requires cgi-lib.pl
require 'cgi-lib.pl';
require 'htmlbbs.pl';
#
# You shouldn't need to touch anything below here
#
# grab values passed from form:
&ReadParse(*in);
# generate a MIME header:
$buf=&PrintHeader;
# print it:
print "$buf\n";
# parse the variables:
&PrintVariables(%in);
# change to your favorite date format:
$date = `date`;
chop($date); # trim \n
# make filenames of the html file and a tmp file
$path = "$ENV{'PATH_TRANSLATED'}";
$tmp = "$path.tmp";
$tmp =~ s/\//@/g; # make a unique tmp file name from the path
$tmp = "/tmp/$tmp";
# print something in the form:
# are we posting or previewing?
if ($in{'what'} eq "post") {
print "HTMLBBS Post Results\n";
} else {
print "HTMLBBS Preview Results\n";
}
# if any fields are blank, then skip the post and inform user:
if (!$in{'name'} || !$in{'address'} || !$in{'body'}) {
&err("Incomplete post. Try again.");
}
# some slight amount of sanity checking for the address:
if ($in{'address'} !~ /^\w+@[\w.-]+$/) {
&err("That doesn't look like a real email address.\nPlease
use an address of the form username@host.domain\n");
}
$text = $in{'body'};
# sanity checking for messages with included HTML tags.
&checkhtml($text);
# reformat the body of the new message. we want to preserve paragraph breaks.
$text =~ s/\r//g;
$text =~ s/\n\n//g;
$text =~ s/\n/ /g;
$text =~ s/
/
/g;
# delete any HTML comments sent to us by malicious people.
# these could hose the file.
# thankx to jsm@crl.com for the tip.
$text =~ s/<\!--.*-->//g;
# if we're previewing, do it now:
if ($in{'what'} eq "preview") {
&preview;
exit(0);
}
# initalize message number counter
$num = 1;
# get an exclusive open on the tmp file, so
# two posts at the same time don't clobber each other.
&getlock($path,$tmp) || &err("can't get lock on $tmp");
# an HTMLBBS file. look through it for the HTML comments
# that denote stuff we want to change:
while() {
if (//) { print TMP " $date \n"; }
elsif (//) {
$num = $_;
# use numbers from existing messages so we can archive messages
# and not replicate numbers
$num =~ s/^.*//;
$num++;
print TMP $_;
}
elsif (//) {
# pointer to last message. skip it as there will be a new
# last message.
;
}
elsif (//) {
print TMP "\n";
$htmlbbs++;
}
elsif (//) {
# add this post
print TMP "\n";
print TMP "";
print TMP "
";
print TMP "$num" if (defined $visible_message_ids);
print TMP "$in{'name'} ";
print TMP " $in{'address'} $date\n";
print TMP "" if (defined $break_after_user);
print TMP "
$text\n\n";
}
else { print TMP $_; } # copy lines
}
&err("$path not an HTMLBBS file!") if (! defined $htmlbbs);
# move the new file over the old and unlock:
&release($path,$tmp);
# print trailing HTML:
print "
\n";
# update the index file:
undef($htmlbbs);
$file = $path;
$file =~ s/^.*\///; # get file name
$path =~ s/\/[^\/]*$//; # get path name
$index = "$path/index.html";
$tmp = "$index.tmp";
&getlock($index,$tmp);
while() {
if (//) {
$htmlbbs++;
}
if(/
$href++;
}
else {
# another HREF
undef $href;
}
}
if (defined $href && //) {
# date tag required to be on it's own line
print TMP " $date\n";
undef($href);
}
else { print TMP $_; } # copy lines
}
&err("not an HTMLBBS file!") if (! defined $htmlbbs);
# move the new file over the old and unlock:
&release($index,$tmp);
1;
sub preview {
print <
$in{'name'}
$in{'address'} $date
$text
If you want to edit your post, go back via your broswer's Back
button edit it. When you
are done and ready to post it, go Back, change
the radio button to POST and click on the SUBMIT button
again. If you are using a
browser that caches (i.e. Netscape 1.1) you will have to
reload the page that you posted to in order to see your post.
GNARLY_EOF
}